package com.sahadev.mvp.presenter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.sahadev.mvp.MVPActivity;
import com.sahadev.mvp.R;
import com.sahadev.mvp.model.NetDataAbst;
import com.sahadev.mvp.other.BaseRecyclerAdapter;
import com.sahadev.mvp.other.BaseRecyclerViewHolder;
import com.sahadev.mvp.view.IView;

import java.lang.reflect.Type;

/**
 * 这里做一个示例
 * Created by Sahadev on 2015/11/12.
 */
public class PresenterImpl extends Presenter{

    /**
     * @param iView 为展示的Activity
     */
    public PresenterImpl(IView iView) {
        super(iView);
        abstIData = new NetDataAbst(this);
    }

    @Override
    public String getTag() {
        return "这里是PresenterImpl";
    }

    @Override
    public RecyclerView.LayoutManager getLayoutManager(Context context) {
        return new GridLayoutManager(context, 3);//这里仅仅做一个示例
    }

    @Override
    public BaseRecyclerAdapter getAdapter(Context context) {
        return new AdapterImpl(context);
    }

    @Override
    public Type getInstanceType() {
        //这里仅仅是用作示例，没有数据需要解析，所以没有也可以
        return null;
    }

    /**
     * 示例ViewHoler，希望以后可以弄成万用的
     */
    public static class ViewHolderImpl extends BaseRecyclerViewHolder {
        TextView textView;

        public ViewHolderImpl(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.text);
        }
    }

    /**
     * 示例适配器
     */
    public class AdapterImpl extends BaseRecyclerAdapter<ViewHolderImpl> {

        public AdapterImpl(Context context) {
            super(context);
        }

        @Override
        public void onBindViewHolder(ViewHolderImpl viewHolder, int i) {
            viewHolder.textView.setText(i + ":" + getTag());//这里完成数据绑定，验证一下是否成功
        }

        @Override
        protected Class<? extends BaseRecyclerViewHolder> getViewHolderClass() {
            return ViewHolderImpl.class;
        }

        @Override
        protected int getInstanceLayoutRes() {
            return R.layout.content_main;
        }
    }


}
